<template>
	<el-dialog :title="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'" :close-on-click-modal="false"
		:visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="1000px">
		<el-row :gutter="15" class="">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="100px" label-position="right"
				:disabled="!!isDetail" :rules="rules">
				<el-col :span="12">
					<el-form-item label="客户名称" prop="customerName">
						<el-input v-model="dataForm.customerName" placeholder="请输入" clearable :style='{ "width": "100%" }'
							prefix-icon="" suffix-icon="">
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="统一社会信用代码" prop="socialCreditCode">
						<el-input v-model="dataForm.socialCreditCode" placeholder="请输入" clearable
							:style='{ "width": "100%" }' prefix-icon="" suffix-icon="">
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="成立日期" prop="">
						<el-date-picker v-model="dataForm.establishmentDate" placeholder="请选择" clearable
							:style='{ "width": "100%" }' type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="法定代表人" prop="legalRepresentative">
						<el-input v-model="dataForm.legalRepresentative" placeholder="请输入" clearable
							:style='{ "width": "100%" }' prefix-icon="" suffix-icon="">
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="注册资本" prop="registeredCapital">
						<el-input v-model="dataForm.registeredCapital" placeholder="请输入" clearable
							:style='{ "width": "100%" }' prefix-icon="" suffix-icon="">
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="注册地址" prop="registeredAddress">
						<el-input v-model="dataForm.registeredAddress" placeholder="请输入" clearable
							:style='{ "width": "100%" }' prefix-icon="" suffix-icon="">
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="行业分类" prop="industryClassification">
						<el-input v-model="dataForm.industryClassification" placeholder="请输入" clearable
							:style='{ "width": "100%" }' prefix-icon="" suffix-icon="">
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="实际经营地址" prop="actualBusinessAddress">
						<el-input v-model="dataForm.actualBusinessAddress" placeholder="请输入" clearable
							:style='{ "width": "100%" }' prefix-icon="" suffix-icon="">
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>

				<el-col :span="12">
					<el-form-item label="主要经营产品" prop="mainProducts">
						<el-input v-model="dataForm.mainProducts" placeholder="请输入" clearable :style='{ "width": "100%" }'
							prefix-icon="" suffix-icon="">
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>

			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
		</span>
	</el-dialog>

</template>
<script>
import request from '@/utils/request'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { previewDataInterface } from '@/api/systemData/dataInterface'
export default {
	data() {
		return {
			visible: false,
			isDetail: false,
			dataForm: {
				customerName: undefined,
				socialCreditCode: undefined,
				establishmentDate: undefined,
				legalRepresentative: undefined,
				registeredCapital: undefined,
				registeredAddress: undefined,
				customerProfile: undefined,
				industryClassification: undefined,
				actualBusinessAddress: undefined,
				actualControllerId: undefined,
				mainProducts: undefined,
				insuredEmployeeCount: undefined,
				nonInsuredEmployeeCount: undefined,
				partTimeEmployeeCount: undefined,
				currentState: undefined,

			},
			rules: {

			},


		}
	},
	created() {

	},
	methods: {

		goBack() {
			this.$emit('refresh')
		},
		init(id, isDetail) {

			this.dataForm.id = id || 0;
			this.visible = true;
			this.isDetail = isDetail || false;
			this.$nextTick(() => {
				this.$refs['elForm'].resetFields();
				if (this.dataForm.id) {
					request({
						url: '/api/Jiushi/Customerbase/' + this.dataForm.id,
						method: 'get'
					}).then(res => {
						this.dataForm = res.data;
            this.getAttachment()
					})
				}
			})
		},
    getAttachment(){
      let query = {
        currentPage: 1,
        pageSize: 20,
        customerId:this.dataForm.id,
        businessId:this.dataForm.businessId
      };
      request({
        url: `/api/Jiushi/Customerattachment`,
        method: 'get',
        data: query
      }).then(res => {
        this.list = res.data.list
        this.total = res.data.pagination.total
        this.listLoading = false
        this.$nextTick(() => {
          this.tableHeight = "100%"
        });
      })
    },
		// 表单提交
		dataFormSubmit() {

			this.$refs['elForm'].validate((valid) => {
				if (valid) {
					if (!this.dataForm.id) {
						request({
							url: '/api/Jiushi/Customerbase',
							method: 'post',
							data: this.dataForm,
						}).then((res) => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.visible = false;
									this.$emit('refresh', true);
								}
							})
						})
					} else {
						request({
							url: '/api/Jiushi/Customerbase/' + this.dataForm.id,
							method: 'PUT',
							data: this.dataForm
						}).then((res) => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.visible = false;
									this.$emit('refresh', true);
								}
							})
						})
					}
				}
			})
		},

	}
}
</script>
